﻿using System.Collections.Generic;
using System.Linq;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.UserModule.Services; 
using Sharp.Domain.Repositories;
using Sharp.Infrastructure.IoC;

namespace Sharp.Domain.PlatformBoundedContext.WorkFlowModule.Engine.Common
{
    /// <summary>
    /// 执行者构造类
    /// </summary>
    public class PerformerBuilder
    {
        private IRepositoryContext _context;
        private IUserService _userService;
        public PerformerBuilder(IRepositoryContext context, IUserService userService)
        {
            _context = context;
            _userService = userService;
        }
        /// <summary>
        /// 创建活动节点执行者列表
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="userName">用户名称</param>
        /// <returns></returns>
        public static PerformerList CreatePerformerList(string userID, string userName)
        {
            var performerList = new PerformerList();
            performerList.Add(new Performer(userID, userName));

            return performerList;
        }


        /// <summary>
        /// 创建活动节点执行者列表
        /// </summary>
        /// <param name="roleList">角色列表</param>
        /// <returns></returns>
        public static PerformerList CreatePerformerList(IList<Role> roleList)
        {
            var roleIDs = roleList.Select(x => x.Id).ToArray();

            var userList = ServiceLocator.Instance.GetService<IUserService>().GetUserListByRoles(roleIDs);
            var performerList = new PerformerList();

            foreach (var user in userList)
            {
                var performer = new Performer(user.Id.ToString(), user.UserName);

                performerList.Add(performer);
            }
            return performerList;
        }
    }
}
